package view;

import java.awt.Color;
import java.awt.Dimension;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JComboBox;
import javax.swing.JPanel;

import model.Conference;
import model.Role;
import model.State;

/**
 * @author Sarah George & kevin Anderson
 *
 */
@SuppressWarnings("serial")
public class RoleListPanel extends JPanel implements Observer {
	
	private JComboBox<Role> my_comboBox;
	private RoleListener my_roleListener;
	
	public RoleListPanel() {
		super();
		setBackground(Color.CYAN);
		setPreferredSize(new Dimension(500, 50));
		my_comboBox = new JComboBox<Role>();
		my_comboBox.setVisible(false);
		this.add(my_comboBox);
		my_roleListener = new RoleListener();
	}

	@Override
	public void update(Observable o, Object arg) {
		if (arg instanceof Conference[]) //this is a new conference load so clear this list.
		{
			my_comboBox.removeAllItems();
			((State) o).allowLogin(false);
		}
		
		if (arg instanceof Role[]) {
			my_comboBox.removeActionListener(my_roleListener);
			my_roleListener.setState((State) o);
			my_comboBox.removeAllItems(); //refresh list before repopulating
			for (Role role : (Role[]) arg)
				my_comboBox.addItem(role);

			
			my_comboBox.addActionListener(my_roleListener);			
			
			my_comboBox.setVisible(true);
			this.validate();
		}
	}

}